using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;

public partial class ActivateCode : System.Web.UI.Page
{
    #region Variables

    public string activateCode
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["id"] == null)
                return "";
            else
                return HttpContext.Current.Request.QueryString["id"];
        }
    }
    public string name
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["username"] == null)
                return "";
            else
                return HttpContext.Current.Request.QueryString["username"];
        }
    }
    Member _Member = new Member();
    MemberCollection _MemberCollection = new MemberCollection();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack)
            return;

        Activate(activateCode);


    }
    #region Activate Code
    protected void Activate(string ActivateCode)
    {
        Criteria cri = new Criteria();
        cri.add(MemberColumns.ActivateCode, ActivateCode, Condition.EQUAL, Condition.AND);
        _MemberCollection = MemberService.GetMemberListByParam("[" + ADESSA.Entities.Member._Table + "].[" + MemberColumns.ActivateCode + "]", OrderDirection.ASC, cri.Criter);

        if (_MemberCollection.Count > 0)
        {
            #region Update Member
            _Member = MemberService.GetMember(_MemberCollection[0].MemberID);
            if (_Member != null)
            {

                LoadContent(_Member.FullName);
                Session["MemberName"] = _Member.FullName;
                Session["MemberId"] = _Member.MemberID;
                _Member.ActivateCode = "";
                //_Member.Status = true;
                MemberService.UpdateMember(_Member);
            }


            #endregion
        }
        else
        {
            LoadActivateOk(this.name);
        }


    }
    #endregion
    #region Load Content
    protected void LoadContent(string name)
    {
        Criteria _cri = new Criteria();
        _cri.add("[" + NewsletterColumns.Order + "]", FetConstant.ActivateThankyou, Condition.EQUAL, Condition.AND);
        NewsletterCollection _NewsletterCollection = NewsletterService.GetNewsletterListByParam("[" + Newsletter._Table + "].[" + NewsletterColumns.CreatedDate + "]", OrderDirection.ASC, _cri.Criter);
        if (_NewsletterCollection != null)
        {
            if (_NewsletterCollection.Count > 0)
            {
                ltrTitle.Text = _NewsletterCollection[0].Title.Replace("Article_", "");
                ltrContent.Text = string.Format(_NewsletterCollection[0].Content, name);
            }
        }
    }
    protected void LoadActivateOk(string name)
    {
        Criteria _cri = new Criteria();
        _cri.add("[" + NewsletterColumns.Order + "]", FetConstant.ActivateOk, Condition.EQUAL, Condition.AND);
        NewsletterCollection _NewsletterCollection = NewsletterService.GetNewsletterListByParam("[" + Newsletter._Table + "].[" + NewsletterColumns.CreatedDate + "]", OrderDirection.ASC, _cri.Criter);
        if (_NewsletterCollection != null)
        {
            if (_NewsletterCollection.Count > 0)
            {
                ltrTitle.Text = _NewsletterCollection[0].Title.Replace("Article_", "");
                ltrContent.Text = string.Format(_NewsletterCollection[0].Content, name);
            }
        }
    }
    #endregion

}
